package com.dapeis.core.utils.json;

import java.lang.reflect.Type;
import java.text.DecimalFormat;

import com.dapeis.domain.MoneyStatistics;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

/** 
 * @author 作者 E-mail: hzyuanyong@126.com
 * @version 创建时间：2017年5月24日 下午4:02:04 
 * 类说明 
 */
public class MoneyStatisticsGsonAdapter implements JsonSerializer<MoneyStatistics>{

    @Override
    public JsonElement serialize(MoneyStatistics src, Type typeOfSrc,
	    JsonSerializationContext context) {
	JsonObject json = new JsonObject();
	json.addProperty("allInComeMoney",paserMoney( src.getAllInComeMoney()));
	json.addProperty("totalMoney", paserMoney(src.getTotalMoney()));
	json.addProperty("freezeMoney",paserMoney( src.getFreezeMoney()));
	json.addProperty("outlayMoney",paserMoney( src.getOutlayMoney()));
	
	json.addProperty("awardSum", paserMoney(src.getAwardSum()));
	json.addProperty("consultingSum",paserMoney( src.getConsultingSum()));
	json.addProperty("shopSum", paserMoney(src.getShopSum()));
	json.addProperty("finishingSum",paserMoney( src.getFinishingSum()));
	json.addProperty("buySum", paserMoney(src.getBuySum()));
	return json;
    }
    
    
    
    public String paserMoney(Object _price) {
	if (null == _price || _price == "" )
	    return "0";
	else {
	    Integer price = new Integer(_price.toString());
	    DecimalFormat decimalFormat = new DecimalFormat("0.00");
	    Float priceFloat = new Float(price);
	    String pasStr = decimalFormat.format(priceFloat / 100);
	    return pasStr;
	}
    }

    

}

